#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSerialPort>        //提供访问串口的功能
#include <QSerialPortInfo>    //提供系统中存在的串口的信息
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
#include <stdio.h>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

#define CARDID_BLOCK   0x01
#define NAME_BLOCK     0x02
#define STUID_BLOCK    0x04
#define BOOKINFO_BLOCK 0x05
#define BOOKPOS_BLOCK  0x06

#define STU_TYPE       0x01
#define BOOK_TYPE      0x02

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void serialport_readyread();
    void on_openButton_clicked();
    void on_searchButton_clicked();
    void on_clearButton_clicked();
    void on_writestuButton_clicked();
    void on_writebookButton_clicked();
    void Read_ICCard_Block(unsigned char block);
    void Write_ICCard_Block(unsigned char block,QByteArray info);

private:
    Ui::MainWindow *ui;
    QSerialPort serialport;
    QByteArray CardId;
    QString Name;
    QString StuId;
    QString BookInfo;
    QString BookName;
    QString BookId;
    QString BookPos;
    int query_mode = NAME_BLOCK;
    int card_type = STU_TYPE;
    QSqlDatabase db;
    QSqlQuery db_result;
    int Set_Count;
    int Set_Mode;
};
#endif // MAINWINDOW_H
